package com.gfxy.modules.items.controller;

import com.alibaba.fastjson.JSONObject;
import com.gfxy.modules.common.entity.MemberList;
import com.gfxy.modules.common.service.IMemberListService;
import com.gfxy.modules.manage.entity.AssessmentItems;
import com.gfxy.modules.manage.service.IAssessmentItemsService;
import com.gfxy.modules.items.entity.teachingresult.TeachingResult;
import com.gfxy.modules.items.service.impl.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.util.SpringContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * @author: lijixin 2021/10/30 11:33 上午
 */
@Api(tags="教学建设公共API")
@RestController
@RequestMapping("/items/AssessmentCommon")
@Slf4j
public class AssessmentCommonController {

    @Autowired
    private IMemberListService memberListService;

    @Autowired
    private IAssessmentItemsService assessmentItemsService;


    @AutoLog(value = "教学建设公共API-获取成员积分")
    @ApiOperation(value="教学建设公共API-获取成员积分", notes="教学建设公共API-获取成员积分")
    @GetMapping(value = "/memberListScores")
    public Result<?> getMemberListScores(
            @RequestParam(name="itemValue")  Integer itemValue,
            @RequestParam(name="totalScore")  Double totalScore,
            @RequestParam(name="memeberNum") Integer memeberNum,
            HttpServletRequest req) {
        AbstractProjectServiceImpl abstractProjectService = getAbstractProjectService(itemValue);
        if(abstractProjectService == null){
            return Result.error("错误的projectType:" + itemValue);
        } else {
            Double[] result = abstractProjectService.getMemberListScore(totalScore,memeberNum);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("scores",result);
            return Result.OK(jsonObject);
        }


    }

    @AutoLog(value = "教学建设公共API-获取年度结果")
    @ApiOperation(value="教学建设公共API-获取年度结果", notes="教学建设公共API-获取年度结果")
    @GetMapping(value = "/itemsResult")
    public Result<?> getTeachingProjectsResult(
            @RequestParam(name="userName") String workNo,
            @RequestParam(name="date") String date,
            @RequestParam(name="projectId") String projectId,
            @RequestParam(name="classificationId") String classificationId){

        List<MemberList> memberLists = memberListService.getMemberListByUserIdAndDate(workNo,date, projectId, classificationId);
        List<TeachingResult> teachingResults = new ArrayList<>();
        for (MemberList memberList : memberLists) {
            int projectType = memberList.getItemValue();
            AbstractProjectServiceImpl abstractProjectService = getAbstractProjectService(projectType);
            try{
                TeachingResult teachingResult = abstractProjectService.getTeachingResultContent(memberList);
                teachingResults.add(teachingResult);
            } catch (Exception e){
                e.printStackTrace();
            }


        }

        return Result.OK(teachingResults);
    }


//    @AutoLog(value = "教学建设公共API-获取年度结果")
//    @ApiOperation(value="教学建设公共API-获取年度结果", notes="教学建设公共API-获取年度结果")
//    @GetMapping(value = "/getTeacherBuildItemDetail")
//    public Result<?> getTeacherBuildItemDetail(@RequestParam(name="itemValue") Integer itemValue,@RequestParam(name="itemId") String itemId){
//        AbstractProjectServiceImpl abstractProjectService = getAbstractProjectService(itemValue);
//        Object gfxyBaseBean = abstractProjectService.getById(itemId);
//        return Result.OK(gfxyBaseBean);
//    }

    public AbstractProjectServiceImpl getAbstractProjectService(int itemValue){

        AssessmentItems item = assessmentItemsService.getItemByItemValue(itemValue);

        AbstractProjectServiceImpl abstractProjectService = SpringContextHolder.getBean(item.getClassComponent());
//        if(itemValue == 1){
//            abstractProjectService = SpringContextHolder.getBean(ZyqjsServiceImpl.class);
//        } else if(itemValue == 2){
//            abstractProjectService = SpringContextHolder.getBean(ZxjpkServiceImpl.class);
//        } else if(itemValue == 3){
//            abstractProjectService = SpringContextHolder.getBean(ZykjsServiceImpl.class);
//        } else if(itemValue == 4){
//            abstractProjectService = SpringContextHolder.getBean(SxjdServiceImpl.class);
//        } else if(itemValue == 5){
//            abstractProjectService = SpringContextHolder.getBean(TYxjcServiceImpl.class);
//        } else if(itemValue == 6){
//            abstractProjectService = SpringContextHolder.getBean(JxmsServiceImpl.class);
//        } else if(itemValue == 7){
//            abstractProjectService = SpringContextHolder.getBean(JxcgServiceImpl.class);
//        } else if(itemValue == 8){
//            abstractProjectService = SpringContextHolder.getBean("");
//        } else if(itemValue == 9){
//            abstractProjectService = SpringContextHolder.getBean(KcszdlbServiceImpl.class);
//        } else if(itemValue == 10){
//            abstractProjectService = SpringContextHolder.getBean(TJxnldsServiceImpl.class);
//        } else if(itemValue == 11){
//            abstractProjectService = SpringContextHolder.getBean(InnovationAndEntrepreneurshipServiceImpl.class);
//        } else if(itemValue == 12){
//            abstractProjectService = SpringContextHolder.getBean(JxtdServiceImpl.class);
//        } else if(itemValue == 13){
//            abstractProjectService = SpringContextHolder.getBean(ZyhyServiceImpl.class);
//        } else if(itemValue == 14){
//            abstractProjectService = SpringContextHolder.getBean(SdyxServiceImpl.class);
//        } else if(itemValue == 15){
//            abstractProjectService = SpringContextHolder.getBean(ZysbServiceImpl.class);
//        } else if(itemValue == 16){
//            abstractProjectService = SpringContextHolder.getBean(RcpyfaServiceImpl.class);
//        } else if(itemValue == 17){
//            abstractProjectService = SpringContextHolder.getBean(TXwsjjdServiceImpl.class);
//        } else if(itemValue == 18) {
//            abstractProjectService = SpringContextHolder.getBean(ZckjServiceImpl.class);
//        } else if(itemValue == 19) {
//            abstractProjectService = SpringContextHolder.getBean(XzwrzServiceImpl.class);
//        } else if(itemValue == 20) {
//            abstractProjectService = SpringContextHolder.getBean(JgxmServiceImpl.class);
//        } else if(itemValue == 21) {
//            abstractProjectService = SpringContextHolder.getBean("");
//        } else if(itemValue == 22) {
//            abstractProjectService = SpringContextHolder.getBean(GfxyTQnjsjkbsServiceImpl.class);
//        } else if(itemValue == 23) {
//            abstractProjectService = SpringContextHolder.getBean(YszpServiceImpl.class);
//        } else if(itemValue == 24) {
//            abstractProjectService = SpringContextHolder.getBean(JndsServiceImpl.class);
//        } else if(itemValue == 25) {
//            abstractProjectService = SpringContextHolder.getBean(TysxServiceImpl.class);
//        } else if(itemValue ==28) {
//            abstractProjectService = SpringContextHolder.getBean(CjrhServiceImpl.class);
//        }

        return abstractProjectService;
    }
}
